function jsonConcat(o1, o2) {
    for (var key in o2) {
        o1[key] = o2[key];
    }
    return o1;
}

function jsonLength(json) {
    var key, count = 0;
    for(key in json) {
        if(json.hasOwnProperty(key)) {
            count++;
        }
    }
    return count;
}

function setAppHeight(){
    var window_height = $(window).height();
    var top_elements_height = $(".header").outerHeight() + $(".topmenu").outerHeight() + $(".tabs").outerHeight();
    var bottom_elements_height = $(".status-message").outerHeight();
    $(".state-wrapper").height((window_height - top_elements_height - bottom_elements_height - 30) + "px");
};
function getURLFragments(){
    //url parametar: ?param=value
    //url fragment: #frag=value
    //funkcija vraca fragmente u json formatu
    var hash = document.location.hash;
    var fragments = hash.split("#")[1].split("&");
    var json = {};
    $.each(fragments, function(key, value){
        json[value.split("=")[0]] = value.split("=")[1];
    });
    return json;
}
function createURL(page, sign, params){
    var ret = page + sign;
    $.each(params, function(key, value){
        ret += key + "=" + value + "&";
    });
    return ret;
};
function getTimeFromString(str,options){
    //po defaultu se str tretira kao "hh:mm", za ostale slucajeve dodati 
    //odgovarajuci parametar u options (nije implementirano jos uvek)
    //2014-04-02 10:54:20
    var date = str.split(" ")[0];
    var time = str.split(" ")[1];
    var year = parseInt(date.split("-")[0]);
    var month = parseInt(date.split("-")[1]);
    var day = parseInt(date.split("-")[2]);
    var hours = parseInt(time.split(":")[0]);
    var minutes = parseInt(time.split(":")[1]);
    var seconds = parseInt(str.split(":")[2]);
    var ret = new Date();
    
    ret.setYear(year);
    ret.setMonth(month-1);
    ret.setDate(day);
    ret.setHours(hours);
    ret.setMinutes(minutes);
    ret.setSeconds(seconds);
    
    return ret.getTime();
};
function getPageURLWithRandomParam(page){
    return page + "?x=" + Math.random();
}
function addUniqueElement(arr, elem){
    if(arr.indexOf(elem) < 0){
        arr.push(elem);
    }
};